package com.sherllinhe.business.controller.admin;

import com.sherllinhe.business.req.TrainCarriageQueryReq;
import com.sherllinhe.business.req.TrainCarriageSaveReq;
import com.sherllinhe.business.req.TrainStationQueryReq;
import com.sherllinhe.business.resp.TrainCarriageQueryResp;
import com.sherllinhe.business.resp.TrainStationQueryResp;
import com.sherllinhe.business.service.TrainCarriageService;
import com.sherllinhe.common.resp.CommonResp;
import com.sherllinhe.common.resp.PageResp;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能：
 * 作者：Sherllin He
 * 日期：2025/4/25 21:10
 */
@RequestMapping("/admin/train-carriage")
@RestController
public class AdminTrainCarriageController {
    @Autowired
    private TrainCarriageService trainCarriageService;

    @PostMapping("/save")
    public CommonResp<Object> register(@Valid @RequestBody TrainCarriageSaveReq req){
        trainCarriageService.save(req);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainCarriageQueryResp>> register(@Valid TrainCarriageQueryReq req){
        PageResp<TrainCarriageQueryResp> list = trainCarriageService.queryList(req);
        return new CommonResp<>(list);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id){
        trainCarriageService.delete(id);
        return new CommonResp<>();
    }

    @GetMapping("/query-by-train-code")
    public CommonResp<PageResp<TrainCarriageQueryResp>> queryByTrainCode(@RequestParam String trainCode, @Valid TrainCarriageQueryReq req){
        PageResp<TrainCarriageQueryResp> list = trainCarriageService.selectByTrainCode(trainCode,req);
        return new CommonResp<>(list);
    }
}
